package com.palmplaystore.bigdata.redis;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;


@Service
public class RedisCluHelper  {
    private String                        systemName="kafka_storm_data_cache";
    @Autowired
    private RedisTemplate<String, String> redisCluTemplate;
    /**
     * 设值
     * 
     * @param key
     * @param value
     */
    public void set(String key, String value,long time,TimeUnit tu) {
    	key=systemName+"_"+key;
    	redisCluTemplate.opsForValue().set(key, value,time,tu);
    }
    public void set(String key, String value) {
    	key=systemName+"_"+key;
    	redisCluTemplate.opsForValue().set(key, value);
    }
    public void del(String key) {
    	key=systemName+"_"+key;
    	redisCluTemplate.delete(key);
    }
    /**
     * 取值
     * 
     * @param key
     * @return
     */
    public String get(String key) {
    	key=systemName+"_"+key;
        return redisCluTemplate.opsForValue().get(key);
    }
    public Map hgetAll(String key) {
    	key=systemName+"_"+key;
    	return redisCluTemplate.boundHashOps(key).entries();
    }
    
    public void hSet(String key,String vk,String value,int time) {
    	key=systemName+"_"+key;
    	redisCluTemplate.boundHashOps(key).expire(time, TimeUnit.MINUTES);
    	redisCluTemplate.boundHashOps(key).put(vk, value);
    }
    public void hdel(String key,String vk) {
    	key=systemName+"_"+key;
    	redisCluTemplate.boundHashOps(key).delete(vk);
    }
}
